package team.group.exam.action;

import java.util.List;
import java.util.Map;

import team.group.exam.biz.IAdminBiz;
import team.group.exam.entity.TbAdmin;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

public class AdminAction implements Action{
    private IAdminBiz adminBiz;
    private TbAdmin admin;
    private List<TbAdmin> adminList;
    private int id;
    /**
     * 分页
     * @return
     */
    private int currentPage;
    private int totalPage;
    
	public TbAdmin getAdmin() {
		return admin;
	}

	public void setAdmin(TbAdmin admin) {
		this.admin = admin;
	}

	public IAdminBiz getAdminBiz() {
		return adminBiz;
	}

	public void setAdminBiz(IAdminBiz adminBiz) {
		this.adminBiz = adminBiz;
	}
	
	
    public List<TbAdmin> getAdminList() {
		return adminList;
	}

	public void setAdminList(List<TbAdmin> adminList) {
		this.adminList = adminList;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	
	
	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	/**
     * 管理员进行后台登录
     */
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
	    adminBiz.getAdminInfo(admin);
	    Map<String, Object> session=ActionContext.getContext().getSession();
	    session.put("adminName",admin.getAdminName());
		return SUCCESS;
	}
	
    /**
     * 新增管理员
     */
	public String addAdmin(){
		adminBiz.addAdminInfo(admin);
		return SUCCESS;
	}
	
	/**
	 * 修改管理员
	 */
	public String updateAdmin(){
		adminBiz.updateAdminInfo(admin);
		return SUCCESS;
	}
	
	/**
	 * 查看管理员列表
	 */
    public String getAdminsInfo(){
    	int pageSize=3;
    	totalPage=adminBiz.getCountPage(pageSize);
		 if(currentPage<=0)
	 		{
			 currentPage=1;
	 		}
	     if(currentPage>=totalPage){
	 			
		     currentPage=totalPage;
	 		}
    	adminList=adminBiz.getAdminsInfo(currentPage,pageSize); 
        return SUCCESS;
    }
    
    /**
     * 查找管理员对象
     */
    public String getAdminInfo(){
    	admin=adminBiz.getAdminById(id);
		return SUCCESS;
    }
    /**
     * 删除管理员
     */
    public String deleteAdmin(){
    	adminBiz.deleteAdminInfo(id);
    	return SUCCESS;
    }
}
